#include "AC33Mxxx_conf.h"


// SCU 
CSP_SCU_T		* const 	SCU 		= (CSP_SCU_T *) SCU_BASE_ADDRESS;

/**
************************************************************************************
* @ Name : CSP_PCU_Init
*
* @ Parameter
*		- scu			SCU
*		- pll_input		XTAL4M_INPUT
*		- prediv
*		- fbctrl
*		- postdiv
*
*
************************************************************************************
*/
void CSP_SCU_PLLEnable (CSP_SCU_T * const scu, UINT32 pll_input, UINT32 prediv, UINT32 fbctrl, UINT32 postdiv)
{
	volatile UINT32		reg_val; 

	//------------------------------------------------------------------------------
	// enable PLL
	//------------------------------------------------------------------------------
	CSP_SCU_SET_PLLCON(scu, (CSP_SCU_GET_PLLCON(scu) | PLLCON_PLLEN)); 



	//------------------------------------------------------------------------------
	// assert PLL Reset
	//------------------------------------------------------------------------------
	CSP_SCU_SET_PLLCON(scu, (CSP_SCU_GET_PLLCON(scu) & ~PLLCON_PLLRSTB)); 



	//------------------------------------------------------------------------------
	// disable PLL Bypass
	//------------------------------------------------------------------------------
	CSP_SCU_SET_PLLCON(scu, (CSP_SCU_GET_PLLCON(scu) | PLLCON_BYPASS_DISABLE)); 



	//------------------------------------------------------------------------------
	// PLL setting 
	//------------------------------------------------------------------------------
	reg_val = CSP_SCU_GET_PLLCON(scu); 
	reg_val &= ~(PLLCON_LOCKSTS|PLLCON_SETTING_MASK); 
	reg_val |= (prediv|fbctrl|(postdiv&PLLCON_POSTDIV_MASK)); 
	CSP_SCU_SET_PLLCON(scu, reg_val); 
	


	//------------------------------------------------------------------------------
	// lift PLL Reset
	//------------------------------------------------------------------------------
	reg_val = CSP_SCU_GET_PLLCON(scu); 
	reg_val &= ~PLLCON_LOCKSTS; 
	reg_val |= PLLCON_PLLRSTB_LIFT; 
	CSP_SCU_SET_PLLCON(scu, reg_val); 
	

	//------------------------------------------------------------------------------
	// examine PLL lock 
	//------------------------------------------------------------------------------
	while(!(CSP_SCU_GET_PLLCON(scu) & PLLCON_LOCKSTS)); 



}

